﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    public class MG9 : Group
    {
        private List<PS> m_PS = new List<PS>();

        public List<PS> PS
        {
            get { return m_PS; }
            set { m_PS = value; }
        }

        public override   string WriteToGroup()
        {
            string ResultStr = "", TempStr;
            string END = "\r\n";

            TempStr = "INPUT GROUP: 9 -- Precipitation station parameters" + END;
            ResultStr += TempStr;

            TempStr = "PRECIPITATION STATION VARIABLES" + END;
            ResultStr += TempStr;


            TempStr = "         Name   Station    X coord.  Y coord." + END;
            ResultStr += TempStr;

            int i = 1;
            foreach (PS myps in this.PS)
            {
                string A = new string(myps.CPNAM);
                TempStr = "! PS" + i.ToString() + "  ='" + A + "'    " + myps.IDPSTA.ToString() + "       " + Math.Round(myps.XPSTA, 3).ToString()
                    + "     " + Math.Round(myps.YPSTA, 3).ToString() + "   " + "  !" + END;

                ResultStr += TempStr;

                i++;

            }

            TempStr = "! END !" + END;
            ResultStr += TempStr;

            //TempStr = StrWriter.GetCLine();  最后一行没有虚线了！！！！
            //ResultStr += TempStr;

            return ResultStr;


            //return "";
        }
        public override   void ReadFromGroup(Dictionary<string, string> dic)
        {
            //int p = -1;
            PS p = new PS();

            foreach (KeyValuePair<string, string> m_dic in dic)
            {
                //p += 1;
                //if (m_dic.Key == "SS" +p)
                //{

                //}
                this.PS.Add(p.ReadFromGroup(m_dic.Value));
            }
        }



      



    }



    public class PS
    {


        //4字符站名，必须包含在单引号中，如'STA1','STA2'
        //前引号必须位于每个记录的第9（或大于9列）
        char[] m_CPNAM = new char[4];

        public char[] CPNAM
        {
            get { return m_CPNAM; }
            set { m_CPNAM = value; }
        }

        //站点编码， 六         位有效数字
        int m_IDPSTA;

        public int IDPSTA
        {
            get { return m_IDPSTA; }
            set { m_IDPSTA = value; }
        }

        //地面站点的X,Y坐标
        double m_XPSTA;

        public double XPSTA
        {
            get { return m_XPSTA; }
            set { m_XPSTA = value; }
        }
        double m_YPSTA;

        public double YPSTA
        {
            get { return m_YPSTA; }
            set { m_YPSTA = value; }
        }

        public PS ReadFromGroup(string str)
        {
            PS p = new PS();

            this.CPNAM = StrWriter.GetString(str, 1).ToCharArray();
            this.IDPSTA = Convert.ToInt32(StrWriter.GetString(str, 2));
            this.XPSTA = Convert.ToDouble(StrWriter.GetString(str, 3));
            this.YPSTA = Convert.ToDouble(StrWriter.GetString(str, 4));


            return p;
        }


    }


}
